/******************************************************************************************************
 * PCB板：   OLD_V2.00.PCB 
 * 单片机：  GD32F450Z
 * 功  能：  ONS3000E UDP协议
 * 文件名:   DUP.C
 * HISTORY:
 *******************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "Includes.h"

/***********************************************************************************************
 * 本模块宏定义
 ***********************************************************************************************/



/***********************************************************************************************
 * 本模块数据结构定义
 ***********************************************************************************************/


/***********************************************************************************************
 * 本模块函数宣言
 ***********************************************************************************************/
/*ONS3000E card信息获取函数*/
/*********************************************************************************/
void doSendRecvCardInfo(u8 *);
void doSendRecvOLPInfo(u8 *);
void doSendRecvALRMInfo(u8 *);
void doGetRemotePWRInfo(u8 *);
/*********************************************************************************/

/*ONS3000E card信息设置函数*/
/*********************************************************************************/
void doSetCardTEMPHIGTHR_UDP(u8 *);
void doSetCardTEMPLOWTHR_UDP(u8 *);
void doSetCardDESCRIP_UDP(u8 *);
void doSetCardPN_UDP(u8 *);
void doSetCardSN_UDP(u8 *);

void doSetOLPALRMTHR_UDP(u8 *);
void doSetOLPABSSWTHR_UDP(u8 *);
void doSetOLPOFFSETSWTHR_UDP(u8 *);

void doSetPGBACKSWMode_UDP(u8 *);
void doSetPGKEYENABLE_UDP(u8 *);
void doSetPGProtectionDir_UDP(u8 *);
void doSetPGHoldOFF_UDP(u8 *);
void doSetSWMODERecoverTime_UDP(u8 *);
void doSetPGWaitToRestoreTime_UDP(u8 *);
void doSetPGTXCYCLE_UDP (u8 *pScanPtr);
void doSetPGAUTOSWType_UDP(u8 *);
void doSetPGSwitchCMDType_UDP(u8 *);
void doSetPGSWMODERecover_UDP(u8 *);


//void doSetPGSFSYNCSW_UDP(u8 *);
void doSetPGSYNCSWCLEAR_UDP(u8 *);
void doSetPumpWorkMode_UDP(u8 *);
void doSetPumpTHR_LOS_UDP(u8 *);
void doSetPumpTHR_LOW_UDP(u8 *);

/*********************************************************************************/

/*********************************************************************************/

/*NET网络设置响应*/
/*********************************************************************************/
void doUDPSetRespond (u8 *);
/*********************************************************************************/

/***********************************************************************************************
 * 外部函数宣言
 ***********************************************************************************************/
extern STATUS WriteEEPRom( USHORT , UCHAR );
extern void EEPROMdataCheck( void );
extern void MoveDefautlToEEPROM( void );

/***********************************************************************************************
 * 外部变量宣言
 ***********************************************************************************************/
extern unsigned char 	RamanBallenceFlag;
extern unsigned char 	RamanPump1BallenceFlag;

/***********************************************************************************************
 * 本模块静态变量定义
 ***********************************************************************************************/
static const FUNTABLEHEX GetcommProtalTLb[]={	

	{	0x0100,		doSendRecvCardInfo		},
	{	0x0200,		doSendRecvOLPInfo			},
	{	0x0300,		doSendRecvALRMInfo		},
	{	0x0402,		doGetRemotePWRInfo		},

	{ 0xFF,			NULL									}//NULL是指令检索结束标志

};

static const FUNTABLEHEX SetcommProtalTLb[]={	

		{ 0x0102,		doSetCardTEMPHIGTHR_UDP				},
		{ 0x0103,		doSetCardTEMPLOWTHR_UDP				},
		{ 0x0105,		doSetCardDESCRIP_UDP					},
		{ 0x0106,		doSetCardPN_UDP								},
		{ 0x0107,		doSetCardSN_UDP								},

		{ 0x0210,		doSetOLPALRMTHR_UDP						},
		{ 0x0211,		doSetOLPABSSWTHR_UDP					},
		{ 0x0212,		doSetOLPOFFSETSWTHR_UDP				},

		{ 0x0300,		doSetPGSwitchCMDType_UDP			},
		{ 0x0301,		doSetPGSWMODERecover_UDP			},
		{ 0x0302,		doSetPGBACKSWMode_UDP					},
		{ 0x0303,		doSetPGKEYENABLE_UDP					},
		{ 0x0304,		doSetPGProtectionDir_UDP			},
		{ 0x0305,		doSetPGAUTOSWType_UDP					},
		{ 0x0306,		doSetPGHoldOFF_UDP						},
		{ 0x0307,		doSetSWMODERecoverTime_UDP		},
		{ 0x0308,		doSetPGWaitToRestoreTime_UDP	},
		{ 0x0309,		doSetPGTXCYCLE_UDP						},

		//{ 0x0400,		doSetPGSFSYNCSW_UDP						},
		{ 0x0401,		doSetPGSYNCSWCLEAR_UDP				},
		
		{ 0x0410,		doSetPumpWorkMode_UDP					},
		{ 0x0411,		doSetPumpTHR_LOS_UDP					},
		{ 0x0412,		doSetPumpTHR_LOW_UDP					},
		

		{ 0xFF,		NULL				}//NULL是指令检索结束标志

};




/***********************************************************************************************
 * 本模块变量定义
 ***********************************************************************************************/
u8 UDPBuff[MAXSENDBUFF];

u8 CurPort;
u8 CurSlot;


/***********************************************************************************************
 * 外部变量宣言
 ***********************************************************************************************/
extern char cStartFlag[2];
extern char downloadFirmareEnable;
extern char downloadParaEnable;
extern unsigned char	baudRateValue;
extern unsigned char	CurUseUSARTID;
extern unsigned char	BootVer;
extern unsigned char UpgradeInterface;
extern unsigned char UpgradeType;

extern ONS3000ECARD 	ONS3ECard;
extern CANBUS   		CANBus;
extern PG_TYPE 	PG;

extern ADCONVERT	AdcChannelData;
extern ALARMTHRESHOLDS	alarmThresholds;
extern ALARMHYSTERESIS   alarmHysteresis;

extern u8 udp_drive_recvbuf[UDP_DRIVE_RX_BUFSIZE];	//UDP接收数据缓冲区

/*NET网络设置响应*/
void doUDPSetRespond (u8 *pScanPtr)
{
	u16 TempData;
	u8 TempByteHig,TempByteLow;
	//SHORTVAR	saveData;
	u8 ucI;
	
	if(ONS3ECard.SetObject == ONS3ECard.RXObject)
	{	
		ONS3ECard.SetCMDSendCount = 0;
		
		switch( ONS3ECard.SetObject )
		{
			case  OLPSWMODESet:
														ONS3ECard.SetDataBuff[1] = ONS3ECard.Addr[0];
														ONS3ECard.SetDataBuff[4] = CANBus.RXPortsave;
														PG.SwitchCMDTypeTemp = udp_drive_recvbuf[FixedDataLen];
														SwitchCMDTypeProcess(0x01);														
														break;	
			
			case  OLPSWDIRSet:
														//PG.ProtectionDirTemp[0] = udp_drive_recvbuf[FixedDataLen];
														ONS3ECard.SetDataBuff[1] = ONS3ECard.Addr[0];
														ONS3ECard.SetDataBuff[4] = CANBus.RXPortsave;
														if(PG.SwitchCMDType[0] == SWCAUSE_MANUAL)
														{
															PG.ProtectionDirection[1] = udp_drive_recvbuf[FixedDataLen];
														}
														else
														{
															ProtectionDirectionProcess(0x01);		
															
															if(PG.SwitchCMDType[0] == SWCAUSE_FORCE)
															PG.SwitchReason[0] = SWCAUSE_FORCE;
															else if(PG.SwitchCMDType[0] == SWCAUSE_SF)
															PG.SwitchReason[0] = SWCAUSE_WTR;
														}															
														break;			
														
			/*case  OLPSFSYNCSWSet:
														pScanPtr++;
														pScanPtr++;
														saveData.ucByte[1] = *pScanPtr++;
														saveData.ucByte[0] = *pScanPtr++;
														
														AdcChannelData.POWER[1][0] = saveData.sWord;
			
														if( (AdcChannelData.POWER[0][0] > ( alarmThresholds.LOS[0][0] + alarmHysteresis.LOS[0] )) && (AdcChannelData.POWER[1][0] > ( alarmThresholds.LOS[1][0] + alarmHysteresis.LOS[0] )))
														{
															ProtectionDirectionProcess(0x01);												
															PG.SwitchReason[0] = SWCAUSE_SF;
														}															
														
														ONS3ECard.SYNCSWFlag = FALSE;
														break;*/															
																											
			case  OLPSYNCSWCLEARSet:
														ONS3ECard.SYNCSWFlag = FALSE;														
														break;														
							
			default:							break;
		}
		
		if(ONS3ECard.SetType == USARTSET)
		{
			//ONS3ECard.SetType = 0x00;
			//ONS3ECard.SetCmdRespondDelayConut = 0;
				
			//USARTPrint("CMD SET SUCC!!!\r\n"  , CurUseUSARTID);
			//USARTPrint("-->"  , CurUseUSARTID);
		
		}
		else if(ONS3ECard.SetType == CANSET)
		{
			for(ucI=0; ucI<(FixedDataLen + ONS3ECard.SetDataLen); ucI++)
			CANBus.TXData[ONS3ECard.CANID][ucI] = ONS3ECard.SetDataBuff[ucI];
			
			CANBus.TXData[ONS3ECard.CANID][1] = ONS3ECard.Addr[0];
			
			TempData = crc16_CCITT(&CANBus.TXData[ONS3ECard.CANID][0],FixedDataLen + CANBus.DataLen[ONS3ECard.CANID]);
			TempByteHig = (TempData>>8)&0xff;
			TempByteLow = TempData&0xff;
			CANBus.TXData[ONS3ECard.CANID][FixedDataLen + CANBus.DataLen[ONS3ECard.CANID]] = TempByteHig;
			CANBus.TXData[ONS3ECard.CANID][FixedDataLen + CANBus.DataLen[ONS3ECard.CANID] + 1] = TempByteLow;
			
			CANBusDataSend(ONS3ECard.CANID,CANBus.DataLen[ONS3ECard.CANID]);
		}
		
		ONS3ECard.SetType = 0x00;
		ONS3ECard.SetCmdRespondDelayConut = 0;
		
		//USARTPrint("CMD SET SUCC!!!\r\n"  , CurUseUSARTID);
		printf("CMD SET: 0x0%x SUCC!!!\r\n",ONS3ECard.SetObject);
		USARTPrint("-->"  , CurUseUSARTID);
		
		if(ONS3ECard.SYNCSWFlag == TRUE)
		SetCmdhandle(OLPSYNCSWCLEARSet , 0x00 , 0x00 , USARTSET);
		else
		SlotCMDSetEXIT();
	}
}


void UDPErrorCommand(UCHAR *pScanPtr)
{
	UCHAR ucI;
	
	if(ONS3ECard.SetType == 0x00 && (udp_drive_recvbuf[2]&0x80) == 0x00)
	{
		UDPBuff[2] |= 1<<7;
		
		CurPort = *pScanPtr++;   		//端口号port 
		UDPBuff[4] = CurPort;
		
		ONS3ECard.DataLen = *pScanPtr++;   //有效数据长度
		UDPBuff[5] = ONS3ECard.DataLen;
		
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		UDPBuff[FixedDataLen + ucI] = *pScanPtr++;
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		//udp_send_flag |= LWIP_SEND_DATA; //标记LWIP有数据要发送
		//ONS3ECard.UDPSenddataLen = FixedDataLen + ONS3ECard.DataLen;
	}
	
}


void UDPProcess( void )
{
	u8 *pScanPtr;
	FUNTABLEHEX *funcTablePtr;		
	u8	commCmdOk = 0;
	u8 TempByteHig;
	u8 TempByteLow;

	pScanPtr = ( u8 *)udp_drive_recvbuf;

	ONS3ECard.CMDType = *pScanPtr++;   //指令类型cmd type
	UDPBuff[0] = ONS3ECard.CMDType;

	CurSlot = *pScanPtr++;   //槽位号slot
	UDPBuff[1] = CurSlot;

	TempByteHig = *pScanPtr++;   //指令对象
	UDPBuff[2] = TempByteHig;
	TempByteLow = *pScanPtr++;   
	UDPBuff[3] = TempByteLow;
	ONS3ECard.RXObject = TempByteHig*256 + TempByteLow;
	
	if(ONS3ECard.CMDType == CMD_Set_Respond)
	{
		doUDPSetRespond(pScanPtr);
			
		return;
	}
	else if(ONS3ECard.CMDType == CMD_Set)
	{
		funcTablePtr = ( FUNTABLEHEX *)&SetcommProtalTLb[0];	
	}
	else
	{
		funcTablePtr = ( FUNTABLEHEX *)&GetcommProtalTLb[0];
	}

	while(funcTablePtr->funcPtr != NULL)
	{
		if( funcTablePtr->commandLine == ONS3ECard.RXObject )
		{
			funcTablePtr->funcPtr( pScanPtr );
			commCmdOk = 1;
		}
		funcTablePtr++;
	}
	
	//无对应命令应答返回格式
	if( commCmdOk == 0 )
	{
		UDPErrorCommand( pScanPtr );
	}
	else
	{
		if(ONS3ECard.TXObject == ONS3ECard.RXObject && udp_drive_recvbuf[5] > 0)
		{	
			ONS3ECard.LSOKFlag = TRUE;
			ONS3ECard.TXSerialNum++;
			ONS3ECard.TXCMDObjectCount = 0;
		}
	}
}


/*获取ONS3000E card信息*/
void doSendRecvCardInfo (u8 *pScanPtr)
{
	u8 ucI;
	SHORTVAR	TempData_s;
	u8 RecvDataLen;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	RecvDataLen = *pScanPtr++;   //接收数据长度
	
	if(CurPort == CARDSELF)
	{
		if(RecvDataLen == 0x00)
		{
			ONS3ECard.DataLen = 126;   			//数据长度
			UDPBuff[5] = ONS3ECard.DataLen;
			
			UDPBuff[0 + FixedDataLen] = ONS3ECard.Addr[0];
			UDPBuff[1 + FixedDataLen] = ONS3ECard.STA[0];
			UDPBuff[2 + FixedDataLen] = ONS3ECard.Type[0];
			UDPBuff[3 + FixedDataLen] = ONS3ECard.FUN[0];		
			UDPBuff[4 + FixedDataLen] = RESERVE;
			UDPBuff[5 + FixedDataLen] = ONS3ECard.PlugSTA[0];
			
			TempData_s.sWord = ONS3ECard.Temp[0];
			UDPBuff[6 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[7 + FixedDataLen] = TempData_s.ucByte[0];
				
			TempData_s.sWord = alarmThresholds.CardMTH[0];
			UDPBuff[8 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[9 + FixedDataLen] = TempData_s.ucByte[0];
				

			TempData_s.sWord = alarmThresholds.CardMTL[0];
			UDPBuff[10 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[11 + FixedDataLen] = TempData_s.ucByte[0];
		
			for(ucI=0; ucI<16; ucI++)
			UDPBuff[12 + FixedDataLen + ucI] = ONS3ECard.PN[0][ucI];
				
			for(ucI=0; ucI<16; ucI++)
			UDPBuff[28 + FixedDataLen + ucI] = ONS3ECard.SN[0][ucI];
				
			for(ucI=0; ucI<16; ucI++)
			UDPBuff[44 + FixedDataLen + ucI] = ONS3ECard.SW[0][ucI];
				
			for(ucI=0; ucI<16; ucI++)
			UDPBuff[60 + FixedDataLen + ucI] = ONS3ECard.HW[0][ucI];
				
			for(ucI=0; ucI<32; ucI++)
			UDPBuff[76 + FixedDataLen + ucI] = ONS3ECard.DESCRIP[0][ucI];	

			for(ucI=0; ucI<16; ucI++)
			UDPBuff[108 + FixedDataLen + ucI] = ONS3ECard.DATE[0][ucI];				
			
			UDPBuff[124 + FixedDataLen] = ONS3ECard.LEDState.Run[0];
			UDPBuff[125 + FixedDataLen] = ONS3ECard.LEDState.Fault[0];
			
			LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		}
		else if(RecvDataLen == 108 || RecvDataLen == 126)
		{
			ONS3ECard.Addr[1] = *pScanPtr++;
			ONS3ECard.STA[1] = *pScanPtr++;
			ONS3ECard.Type[1] = *pScanPtr++;
			ONS3ECard.FUN[1] = *pScanPtr++;
			pScanPtr++;
			ONS3ECard.PlugSTA[1] = *pScanPtr++;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			ONS3ECard.Temp[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			alarmThresholds.CardMTH[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			alarmThresholds.CardMTL[1] = TempData_s.sWord;
			
			for(ucI=0; ucI<16; ucI++)
			ONS3ECard.PN[1][ucI] = *pScanPtr++;
			
			for(ucI=0; ucI<16; ucI++)
			ONS3ECard.SN[1][ucI] = *pScanPtr++;
			
			for(ucI=0; ucI<16; ucI++)
			ONS3ECard.SW[1][ucI] = *pScanPtr++;
			
			for(ucI=0; ucI<16; ucI++)
			ONS3ECard.HW[1][ucI] = *pScanPtr++;
			
			for(ucI=0; ucI<32; ucI++)
			ONS3ECard.DESCRIP[1][ucI] = *pScanPtr++;
			
			for(ucI=0; ucI<16; ucI++)
			ONS3ECard.DATE[1][ucI] = *pScanPtr++;
			
			ONS3ECard.LEDState.Run[1] = *pScanPtr++;
			ONS3ECard.LEDState.Fault[1] = *pScanPtr++;
		}
	}
}




/*获取OLP信息*/
void doSendRecvOLPInfo (u8 *pScanPtr)
{
	u8 RecvDataLen;
	u8 ucI;
	USHORTVAR	TempData_u;
	SHORTVAR	TempData_s;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	RecvDataLen = *pScanPtr++;   //接收数据长度
	
	if(CurPort == CARDSELF)
	{
		if(RecvDataLen == 0x00)
		{
			ONS3ECard.DataLen = 84;   			//数据长度
			UDPBuff[5] = ONS3ECard.DataLen;
			
			/*if(PG.SelectedPort[0] == PG.PrimaryPort[0])
			PG.CURCH_RX[0] = 0x00;	
			else if(PG.SelectedPort[0] == PG.SecondaryPort[0])
			PG.CURCH_RX[0] = 0x01;*/	
			
			UDPBuff[0 + FixedDataLen] = PG.CURCH_RX[0];
			UDPBuff[1 + FixedDataLen] = PG.SwitchCMDType[0];
			UDPBuff[2 + FixedDataLen] = PG.SWMODERecover[0];
			UDPBuff[3 + FixedDataLen] = PG.BackSWMode[0];
			UDPBuff[4 + FixedDataLen] = PG.KEYEnable[0];
			UDPBuff[5 + FixedDataLen] = PG.ProtectionDirection[0];	
			UDPBuff[6 + FixedDataLen] = PG.AUTOSW_TYPE[0];
			UDPBuff[7 + FixedDataLen] = PG.REMOTESTA[0];
			
			TempData_u.usWord = PG.HoldOFF[0];	
			UDPBuff[8 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[9 + FixedDataLen] = TempData_u.ucByte[0];
			
			TempData_u.usWord = PG.SWMODERecoverTime[0];	
			UDPBuff[10 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[11 + FixedDataLen] = TempData_u.ucByte[0];

			TempData_u.usWord = PG.WaitToRestoreTime[0];	
			UDPBuff[12 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[13 + FixedDataLen] = TempData_u.ucByte[0];

			TempData_u.usWord = PG.SWCount[0];	
			UDPBuff[14 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[15 + FixedDataLen] = TempData_u.ucByte[0];

			for(ucI=0; ucI<6; ucI++)
			{
				TempData_s.sWord = AdcChannelData.POWER[0][ucI];	
				UDPBuff[16 + FixedDataLen + 4*ucI] = TempData_s.ucByte[1];
				UDPBuff[17 + FixedDataLen + 4*ucI] = TempData_s.ucByte[0];
				
				TempData_s.sWord = alarmThresholds.LOS[0][ucI];	
				UDPBuff[18 + FixedDataLen + 4*ucI] = TempData_s.ucByte[1];
				UDPBuff[19 + FixedDataLen + 4*ucI] = TempData_s.ucByte[0];		
			}
			
			TempData_s.sWord = PG.ABSTHR[0][0];	
			UDPBuff[40 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[41 + FixedDataLen] = TempData_s.ucByte[0];	
			
			TempData_s.sWord = PG.ABSTHR[0][1];	
			UDPBuff[42 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[43 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = PG.OFFSETTHR[0][0];	
			UDPBuff[44 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[45 + FixedDataLen] = TempData_s.ucByte[0];	
			
			TempData_s.sWord = PG.OFFSETTHR[0][1];	
			UDPBuff[46 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[47 + FixedDataLen] = TempData_s.ucByte[0];		
			
			UDPBuff[48 + FixedDataLen] = ONS3ECard.LEDState.AFIND[0];	
			UDPBuff[49 + FixedDataLen] = ONS3ECard.LEDState.PSSTAIND[0];
			UDPBuff[50 + FixedDataLen] = ONS3ECard.LEDState.R1ALRMIND[0];
			UDPBuff[51 + FixedDataLen] = ONS3ECard.LEDState.R2ALRMIND[0];
			UDPBuff[52 + FixedDataLen] = ONS3ECard.LEDState.TXALRMIND[0];
			UDPBuff[53 + FixedDataLen] = ONS3ECard.LEDState.LSLINKIND[0];
			UDPBuff[54 + FixedDataLen] = ONS3ECard.CanBackSwFlag[0];
			UDPBuff[55 + FixedDataLen] = PG.CURCH_TX[0];
			UDPBuff[56 + FixedDataLen] = PG.TXCycle[0];
			
			TempData_s.sWord = ONS3ECard.signalPower[0];	
			UDPBuff[57 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[58 + FixedDataLen] = TempData_s.ucByte[0];
			
			UDPBuff[59 + FixedDataLen] = ONS3ECard.OpMode[0];
			
			TempData_u.usWord = ONS3ECard.pump1ISPSet[0];	
			UDPBuff[60 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[61 + FixedDataLen] = TempData_u.ucByte[0];
			
			TempData_u.usWord = ONS3ECard.ramanGainSet[0];	
			UDPBuff[62 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[63 + FixedDataLen] = TempData_u.ucByte[0];
			
			TempData_u.usWord = ONS3ECard.wave1Powerset[0];	
			UDPBuff[64 + FixedDataLen] = TempData_u.ucByte[1];
			UDPBuff[65 + FixedDataLen] = TempData_u.ucByte[0];
			
			TempData_s.sWord = AdcChannelData.PumpILD[0];	
			UDPBuff[66 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[67 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = ONS3ECard.PCT1;	
			UDPBuff[68 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[69 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = AdcChannelData.PumpOp[0];	
			UDPBuff[70 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[71 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = AdcChannelData.PumpTs[0];	
			UDPBuff[72 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[73 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = AdcChannelData.PumpTec[0];	
			UDPBuff[74 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[75 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = alarmThresholds.Signal[0];	
			UDPBuff[76 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[77 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = alarmThresholds.Low[0];	
			UDPBuff[78 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[79 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = AdcChannelData.POWER[0][6];	
			UDPBuff[80 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[81 + FixedDataLen] = TempData_s.ucByte[0];
			
			TempData_s.sWord = alarmThresholds.LOS[0][6];	
			UDPBuff[82 + FixedDataLen] = TempData_s.ucByte[1];
			UDPBuff[83 + FixedDataLen] = TempData_s.ucByte[0];	

			LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);			
		}
		else if(RecvDataLen == 84)
		{
			PG.CURCH_RX[1] = *pScanPtr++;
			PG.SwitchCMDType[1] = *pScanPtr++;
			PG.SWMODERecover[1] = *pScanPtr++;
			PG.BackSWMode[1] = *pScanPtr++;
			PG.KEYEnable[1] = *pScanPtr++;
			PG.ProtectionDirection[1] = *pScanPtr++;
			PG.AUTOSW_TYPE[1] = *pScanPtr++;
			PG.REMOTESTA[1] = *pScanPtr++;
	
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			PG.HoldOFF[1] = TempData_u.usWord;
			
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			PG.SWMODERecoverTime[1] = TempData_u.usWord;
			
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			PG.WaitToRestoreTime[1] = TempData_u.usWord;
			
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			PG.SWCount[1] = TempData_u.usWord;
			
			for(ucI=0; ucI<6; ucI++)
			{
				TempData_s.ucByte[1] = *pScanPtr++;
				TempData_s.ucByte[0] = *pScanPtr++;
				AdcChannelData.POWER[1][ucI] = TempData_s.sWord;
				
				TempData_s.ucByte[1] = *pScanPtr++;
				TempData_s.ucByte[0] = *pScanPtr++;
				 alarmThresholds.LOS[1][ucI] = TempData_s.sWord;
			}
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.ABSTHR[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.ABSTHR[1][1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.OFFSETTHR[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.OFFSETTHR[1][1] = TempData_s.sWord;
			
			ONS3ECard.LEDState.AFIND[1] = *pScanPtr++;
			ONS3ECard.LEDState.PSSTAIND[1] = *pScanPtr++;
			ONS3ECard.LEDState.R1ALRMIND[1] = *pScanPtr++;
			ONS3ECard.LEDState.R2ALRMIND[1] = *pScanPtr++;
			ONS3ECard.LEDState.TXALRMIND[1] = *pScanPtr++;
			ONS3ECard.LEDState.LSLINKIND[1] = *pScanPtr++;
			ONS3ECard.CanBackSwFlag[1] = *pScanPtr++;
			PG.CURCH_TX[1] = *pScanPtr++;
			PG.TXCycle[1] = *pScanPtr++;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			ONS3ECard.signalPower[1] = TempData_s.sWord;
			
			ONS3ECard.OpMode[1] = *pScanPtr++;
			
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			ONS3ECard.pump1ISPSet[1] = TempData_u.usWord;
			
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			ONS3ECard.ramanGainSet[1] = TempData_u.usWord;
			
			TempData_u.ucByte[1] = *pScanPtr++;
			TempData_u.ucByte[0] = *pScanPtr++;
			ONS3ECard.wave1Powerset[1] = TempData_u.usWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.PumpILD[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			ONS3ECard.PCT1_remote = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.PumpOp[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.PumpTs[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.PumpTec[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			alarmThresholds.Signal[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			alarmThresholds.Low[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][6] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			alarmThresholds.LOS[1][6] = TempData_s.sWord;
		}
	}
}



/*获取ONS3000E 0x0300命令告警信息*/
void doSendRecvALRMInfo (u8 *pScanPtr)
{
	u8 RecvDataLen;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	RecvDataLen = *pScanPtr++;   //接收数据长度
	
	if(CurPort == CARDSELF)
	{
		if(RecvDataLen == 0x00)
		{
			ONS3ECard.DataLen = 4;   			//数据长度
			UDPBuff[5] = ONS3ECard.DataLen;
			
			UDPBuff[0 + FixedDataLen] = ONS3ECard.ALRMInfo[0][0];
			UDPBuff[1 + FixedDataLen] = ONS3ECard.ALRMInfo[0][1];
			UDPBuff[2 + FixedDataLen] = Reserve;
			UDPBuff[3 + FixedDataLen] = Reserve;
			
			LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		}
		else if(RecvDataLen == 4)
		{
			ONS3ECard.ALRMInfo[1][0] = *pScanPtr++;
			ONS3ECard.ALRMInfo[1][1] = *pScanPtr++;
		}
	}	
}

/*获取对端当前光功率信息*/
void doGetRemotePWRInfo (u8 *pScanPtr)
{
	u8 RecvDataLen;
	SHORTVAR	TempData_s;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	RecvDataLen = *pScanPtr++;   //接收数据长度
	
	if(CurPort == CARDSELF)
	{
		if(RecvDataLen == 0x10) //对端接收到本端请求 local-->remote
		{
			ONS3ECard.Respond_remote_OptPwr_Flag = TRUE;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][3] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][5] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			ONS3ECard.signalPower[1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.ABSTHR[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.ABSTHR[1][1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.OFFSETTHR[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.OFFSETTHR[1][1] = TempData_s.sWord;
		}
		else if(RecvDataLen == 0x11)  //本端接收到对端响应  remote-->local
		{
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][3] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			AdcChannelData.POWER[1][5] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			ONS3ECard.signalPower[1] = TempData_s.sWord;
			
			ONS3ECard.remote_OptPwr_Respond_num = *pScanPtr++;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.ABSTHR[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.ABSTHR[1][1] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.OFFSETTHR[1][0] = TempData_s.sWord;
			
			TempData_s.ucByte[1] = *pScanPtr++;
			TempData_s.ucByte[0] = *pScanPtr++;
			PG.OFFSETTHR[1][1] = TempData_s.sWord;
			
			ONS3ECard.remote_OptPwr_Request_count++;
			if(ONS3ECard.remote_OptPwr_Request_count >= PG.TXCycle[0])
			{
				ONS3ECard.remote_OptPwr_Request_count = 0;
				
				ONS3ECard.Request_remote_OptPwr_over_Flag = TRUE;
			}
			else
			{
				ONS3ECard.Request_remote_OptPwr_Flag = TRUE;
				
				ONS3ECard.R1_R2_OptPwr_LOS_count = 0;
			}
		}
	}	
}


//设置ONS3000E Card高温门限
void doSetCardTEMPHIGTHR_UDP (u8 *pScanPtr)
{
	u8 TempByteHig,TempByteLow;
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF)
	{	
		UDPBuff[0] |= 1<<7;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		TempByteHig = *pScanPtr++;
		TempByteLow = *pScanPtr++;
		UDPBuff[6] = TempByteHig;
		UDPBuff[7] = TempByteLow;

		saveData.sWord = (TempByteHig<<8) + TempByteLow;
		alarmThresholds.CardMTH[0] = saveData.sWord;
		WriteEEPRom( ADDR_THRESHOLD_CARDMTH ,saveData.ucByte[0] );
		WriteEEPRom( ADDR_THRESHOLD_CARDMTH + 1 ,saveData.ucByte[1] );
		
		ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_CARDMTH] = saveData.ucByte[0];
		ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_CARDMTH + 1] = saveData.ucByte[1];
		EEPROMdataCheck();
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
		ONS3ECard.DataLen = 0x00;			
		UDPBuff[5] = ONS3ECard.DataLen;
	}
}


//设置ONS3000E Card低温门限
void doSetCardTEMPLOWTHR_UDP (u8 *pScanPtr)
{
	u8 TempByteHig,TempByteLow;
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF)
	{	
		UDPBuff[0] |= 1<<7;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		TempByteHig = *pScanPtr++;
		TempByteLow = *pScanPtr++;
		UDPBuff[6] = TempByteHig;
		UDPBuff[7] = TempByteLow;

		saveData.sWord = (TempByteHig<<8) + TempByteLow;
		alarmThresholds.CardMTL[0] = saveData.sWord;
		WriteEEPRom( ADDR_THRESHOLD_CARDMTL ,saveData.ucByte[0] );
		WriteEEPRom( ADDR_THRESHOLD_CARDMTL + 1 ,saveData.ucByte[1] );
		
		ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_CARDMTL] = saveData.ucByte[0];
		ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_CARDMTL + 1] = saveData.ucByte[1];
		EEPROMdataCheck();
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
		ONS3ECard.DataLen = 0x00;			
		UDPBuff[5] = ONS3ECard.DataLen;
	}
}

//设置OLP 端口的告警门限
void doSetOLPALRMTHR_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort >= PORT1 && CurPort<= PORT7)
	{
		UDPBuff[0] |= 1<<7;
									
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.sWord >= ONS3ECard.thresholdMin[CurPort - 1] && saveData.sWord <= ONS3ECard.thresholdMax[CurPort - 1])
		{
			alarmThresholds.LOS[0][CurPort - 1] = saveData.sWord;
			WriteEEPRom( ADDR_THRESHOLD_LOS + 2*(CurPort - 1), saveData.ucByte[0] );
			WriteEEPRom( ADDR_THRESHOLD_LOS + 2*(CurPort - 1) + 1, saveData.ucByte[1] );
				
			ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_LOS + 2*(CurPort - 1)] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_LOS + 2*(CurPort - 1) + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}

//设置OLP 端口的绝对倒换门限
void doSetOLPABSSWTHR_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort >= PORT1 && CurPort<= PORT2)
	{
		UDPBuff[0] |= 1<<7;
									
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.sWord >= ONS3ECard.thresholdMin[CurPort - 1] && saveData.sWord <= ONS3ECard.thresholdMax[CurPort - 1])
		{		
			PG.ABSTHR[0][CurPort - 1] = saveData.sWord;
			WriteEEPRom( ADDR_PG_ABSTHR + 2*(CurPort - 1), saveData.ucByte[0] );
			WriteEEPRom( ADDR_PG_ABSTHR + 2*(CurPort - 1) + 1, saveData.ucByte[1] );
				
			ONS3ECard.EEPROMBuff[ADDR_PG_ABSTHR + 2*(CurPort - 1)] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_PG_ABSTHR + 2*(CurPort - 1) + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}

//设置OLP 端口的相对倒换门限
void doSetOLPOFFSETSWTHR_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort >= PORT1 && CurPort<= PORT2)
	{
		UDPBuff[0] |= 1<<7;
									
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.sWord >= ONS3ECard.thresholdMin[CurPort - 1] && saveData.sWord <= ONS3ECard.thresholdMax[CurPort - 1])
		{				
			PG.OFFSETTHR[0][CurPort - 1] = saveData.sWord;
			WriteEEPRom( ADDR_PG_OFFSETTHR + 2*(CurPort - 1), saveData.ucByte[0] );
			WriteEEPRom( ADDR_PG_OFFSETTHR + 2*(CurPort - 1) + 1, saveData.ucByte[1] );
				
			ONS3ECard.EEPROMBuff[ADDR_PG_OFFSETTHR + 2*(CurPort - 1)] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_PG_OFFSETTHR + 2*(CurPort - 1) + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG SwitchCMDType 倒换命令类型*/
void doSetPGSwitchCMDType_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		PG.SwitchCMDTypeTemp = *pScanPtr++;
		UDPBuff[6] = PG.SwitchCMDTypeTemp;

		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		SwitchCMDTypeProcess(SavePort);
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG SWMODERecover 倒换模式恢复*/
void doSetPGSWMODERecover_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		PG.SWMODERecover[SavePort -1] = *pScanPtr++;
		UDPBuff[6] = PG.SWMODERecover[SavePort- 1];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		//SWMODERecoverCheck();
				
		WriteEEPRom( ADDR_PG_SWMODERecover, PG.SWMODERecover[SavePort -1] );
		ONS3ECard.EEPROMBuff[ADDR_PG_SWMODERecover] = PG.SWMODERecover[SavePort -1];
		EEPROMdataCheck();
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG BackSWMode 回切模式*/
void doSetPGBACKSWMode_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		PG.BackSWMode[SavePort -1] = *pScanPtr++;
		UDPBuff[6] = PG.BackSWMode[SavePort -1];
				
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		WriteEEPRom( ADDR_PG_BACKSWMode, PG.BackSWMode[SavePort -1] );
		ONS3ECard.EEPROMBuff[ADDR_PG_BACKSWMode] = PG.BackSWMode[SavePort -1];
		EEPROMdataCheck();
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG KEYENABLE 按键使能*/
void doSetPGKEYENABLE_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		PG.KEYEnable[SavePort -1] = *pScanPtr++;
		UDPBuff[6] = PG.KEYEnable[SavePort -1];
				
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		WriteEEPRom( ADDR_PG_KEYENABLE, PG.KEYEnable[SavePort -1] );
		ONS3ECard.EEPROMBuff[ADDR_PG_KEYENABLE] = PG.KEYEnable[SavePort -1];
		EEPROMdataCheck();
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG ProtectionDir 倒换方向*/
void doSetPGProtectionDir_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		if( (AdcChannelData.POWER[0][0] > ( alarmThresholds.LOS[0][0] + alarmHysteresis.LOS[0] )) && (AdcChannelData.POWER[1][0] > ( alarmThresholds.LOS[1][0] + alarmHysteresis.LOS[0] )))
		{
			UDPBuff[0] |= 1<<7;
			SavePort = 0x01;
			
			ONS3ECard.SYNCSWFlag = TRUE;
			
			ONS3ECard.DataLen = *pScanPtr++;
			UDPBuff[5] = ONS3ECard.DataLen;

			PG.ProtectionDirTemp = *pScanPtr++;
			
			if(PG.ProtectionDirTemp == BackSwToPri)
			{
				if( (ONS3ECard.signalPower[0] > ( PG.ABSTHR[0][0] + alarmHysteresis.LOS[3] )) && PG.BackSWMode[0] == ENABLE )  //回切的时候要判断当前线路是不是OK的
				{
					PG.ProtectionDirTemp = ToPrimary;
					UDPBuff[6] = PG.ProtectionDirTemp;
				
					LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
					
					delay_ms(5);
					//delay_ms(100);
					ProtectionDirectionProcess(SavePort);	
					
					if(PG.SwitchCMDType[1] == SWCAUSE_FORCE)
					PG.SwitchReason[0] = SWCAUSE_FORCE;
					else if(PG.SwitchCMDType[1] == SWCAUSE_SF)
					PG.SwitchReason[0] = SWCAUSE_WTR;
				}
			}
			else
			{
				UDPBuff[6] = PG.ProtectionDirTemp;
				
				LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
				
				delay_ms(5);
				//delay_ms(100);
				ProtectionDirectionProcess(SavePort);	
				
				if(PG.SwitchCMDType[1] == SWCAUSE_FORCE)
				PG.SwitchReason[0] = SWCAUSE_FORCE;
				else if(PG.SwitchCMDType[1] == SWCAUSE_SF)
				PG.SwitchReason[0] = SWCAUSE_WTR;
			}
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG AUTOSWType 自动倒换类型*/
void doSetPGAUTOSWType_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		PG.AUTOSW_TYPE[SavePort -1] = *pScanPtr++;
		UDPBuff[6] = PG.AUTOSW_TYPE[SavePort -1];
				
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		WriteEEPRom( ADDR_PG_AUTOSWTYPE, PG.AUTOSW_TYPE[SavePort -1] );
		ONS3ECard.EEPROMBuff[ADDR_PG_AUTOSWTYPE] = PG.AUTOSW_TYPE[SavePort -1];
		EEPROMdataCheck();		
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG HoldOFF 延时倒换的时间*/
void doSetPGHoldOFF_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.sWord >= 0 && saveData.sWord <= 32767)
		{
			PG.HoldOFF[SavePort -1] = saveData.sWord;
			WriteEEPRom( ADDR_PG_HoldOFF, saveData.ucByte[0] );
			WriteEEPRom( ADDR_PG_HoldOFF + 1, saveData.ucByte[1] );
				
			ONS3ECard.EEPROMBuff[ADDR_PG_HoldOFF] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_PG_HoldOFF + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}		
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG SWMODERecoverTime 自动模式恢复时间*/
void doSetSWMODERecoverTime_UDP (u8 *pScanPtr)
{
	USHORTVAR	saveData;
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.usWord >= 1 && saveData.usWord <= 65535)
		{
			PG.SWMODERecoverTime[SavePort -1] = saveData.usWord;
			WriteEEPRom( ADDR_PG_RecoverTime, saveData.ucByte[0] );
			WriteEEPRom( ADDR_PG_RecoverTime + 2*(0) + 1, saveData.ucByte[1] );
				
			ONS3ECard.EEPROMBuff[ADDR_PG_RecoverTime] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_PG_RecoverTime + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}		
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PG WaitToRestoreTime 回切延时时间*/
void doSetPGWaitToRestoreTime_UDP (u8 *pScanPtr)
{
	USHORTVAR	saveData;
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.usWord >= 1 && saveData.usWord <= 65535)
		{
			PG.WaitToRestoreTime[SavePort -1] = saveData.usWord;
			WriteEEPRom( ADDR_PG_RestoreTime, saveData.ucByte[0] );
			WriteEEPRom( ADDR_PG_RestoreTime + 2*(0) + 1, saveData.ucByte[1] );
				
			ONS3ECard.EEPROMBuff[ADDR_PG_RestoreTime] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_PG_RestoreTime + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}	
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}

/*设置PG TXCYCLE  对端TX光功率轮询周期*/
void doSetPGTXCYCLE_UDP (u8 *pScanPtr)
{
	u8 SavePort;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		PG.TXCycle[SavePort -1] = *pScanPtr++;
		UDPBuff[6] = PG.TXCycle[SavePort -1];
				
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		WriteEEPRom( ADDR_PG_TXCycle, PG.TXCycle[SavePort -1] );
		ONS3ECard.EEPROMBuff[ADDR_PG_TXCycle] = PG.TXCycle[SavePort -1];
		EEPROMdataCheck();
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}



/*设置PG SF同步倒换*/
/*void doSetPGSFSYNCSW_UDP (u8 *pScanPtr)
{
	SHORTVAR	TempData_s;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF || CurPort == PORT1)
	{	
		UDPBuff[0] |= 1<<7;

		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		TempData_s.ucByte[1] = *pScanPtr++;
		TempData_s.ucByte[0] = *pScanPtr++;
		
		AdcChannelData.POWER[1][0] = TempData_s.sWord;
		PG.ProtectionDirTemp = CurPort;
		
		ONS3ECard.Respond_sync_SW_Flag = TRUE;
		
		if(ONS3ECard.Respond_sync_SW_Flag == TRUE)
		{
			ONS3ECard.Respond_sync_SW_Flag = FALSE;
			
			//Respond_sync_switch();
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}*/

/*设置PG 同步倒换清除操作*/
void doSetPGSYNCSWCLEAR_UDP (u8 *pScanPtr)
{
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF)
	{	
		UDPBuff[0] |= 1<<7;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		UDPBuff[6] = *pScanPtr++;
				
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		ONS3ECard.SYNCSWFlag = FALSE;
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


/*设置PUMP 工作模式和参数*/
void doSetPumpWorkMode_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;
	u8 SavePort;
	u8 WorkMode;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{	
		UDPBuff[0] |= 1<<7;
		SavePort = 0x01;
		
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;
		
		WorkMode = *pScanPtr++;
		UDPBuff[6] = WorkMode;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[7] = saveData.ucByte[1];
		UDPBuff[8] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if ( WorkMode == DISABLE_MODE )				
		{					
			ONS3ECard.SoftwareShutFlag = ENABLE;
			ONS3ECard.PreOpMode = ONS3ECard.OpMode[0];
			ONS3ECard.OpMode[0] = DISABLE_MODE;
			
			RamanBallenceFlag = DISABLE;
			RamanPump1BallenceFlag = FALSE;
			
			WriteEEPRom( ADDR_OPMODE, WorkMode );
			ONS3ECard.EEPROMBuff[ADDR_OPMODE] = WorkMode;
			
			EEPROMdataCheck();
		}else if ( WorkMode == MANUAL_MODE )				
		{					
			if(saveData.sWord >= 1 && saveData.sWord <= ONS3ECard.PC1)
			{
				ONS3ECard.SoftwareShutFlag = DISABLE;
				ONS3ECard.PreOpMode = ONS3ECard.OpMode[0];
				ONS3ECard.OpMode[0] = MANUAL_MODE;
				
				RamanBallenceFlag = DISABLE;
				RamanPump1BallenceFlag = FALSE;
				
				ONS3ECard.pump1ISPSet[SavePort - 1] = saveData.sWord;
				WriteEEPRom( ADDR_PUMP1_CURRENT, saveData.ucByte[0] );
				WriteEEPRom( ADDR_PUMP1_CURRENT + 1, saveData.ucByte[1] );
				ONS3ECard.EEPROMBuff[ADDR_PUMP1_CURRENT] = saveData.ucByte[0];
				ONS3ECard.EEPROMBuff[ADDR_PUMP1_CURRENT + 1] = saveData.ucByte[1];
				
				WriteEEPRom( ADDR_OPMODE, WorkMode );
				ONS3ECard.EEPROMBuff[ADDR_OPMODE] = WorkMode;
				
				EEPROMdataCheck();
			}
			else
			{
				UDPBuff[2] |= 1<<7;
			}
		}else if ( WorkMode == GAIN_MODE )				
		{					
			if(saveData.sWord >= ONS3ECard.ramangainSetMin && saveData.sWord <= ONS3ECard.ramangainSetMax)
			{
				ONS3ECard.SoftwareShutFlag = DISABLE;
				ONS3ECard.PreOpMode = ONS3ECard.OpMode[0];
				ONS3ECard.OpMode[0] = GAIN_MODE;

				ONS3ECard.ramanGainSet[0] = saveData.sWord;
				WriteEEPRom( ADDR_TOTAL_GAINSET, saveData.ucByte[0] );
				WriteEEPRom( ADDR_TOTAL_GAINSET + 1, saveData.ucByte[1] );
				ONS3ECard.EEPROMBuff[ADDR_TOTAL_GAINSET] = saveData.ucByte[0];
				ONS3ECard.EEPROMBuff[ADDR_TOTAL_GAINSET + 1] = saveData.ucByte[1];
						
				WriteEEPRom( ADDR_OPMODE, WorkMode );
				ONS3ECard.EEPROMBuff[ADDR_OPMODE] = WorkMode;
				
				EEPROMdataCheck();
			}
			else
			{
				UDPBuff[2] |= 1<<7;
			}
		}else if ( WorkMode == POWER_MODE )				
		{					
			if(saveData.sWord >= 1 && saveData.sWord <= ONS3ECard.PP1)
			{
				ONS3ECard.SoftwareShutFlag = DISABLE;
				ONS3ECard.PreOpMode = ONS3ECard.OpMode[0];
				ONS3ECard.OpMode[0] = POWER_MODE;

				ONS3ECard.wave1Powerset[0] = saveData.sWord;
				ONS3ECard.pumpPowerSet = ONS3ECard.wave1Powerset[0];
				WriteEEPRom( ADDR_WAVE1_PUMPPOWERSET, saveData.ucByte[0] );	
				WriteEEPRom( ADDR_WAVE1_PUMPPOWERSET + 1, saveData.ucByte[1] );
				ONS3ECard.EEPROMBuff[ADDR_WAVE1_PUMPPOWERSET] = saveData.ucByte[0];
				ONS3ECard.EEPROMBuff[ADDR_WAVE1_PUMPPOWERSET + 1] = saveData.ucByte[1];
						
				WriteEEPRom( ADDR_OPMODE, WorkMode );
				ONS3ECard.EEPROMBuff[ADDR_OPMODE] = WorkMode;
				
				EEPROMdataCheck();
			}
			else
			{
				UDPBuff[2] |= 1<<7;
			}
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}


//设置PUMP LOS门限
void doSetPumpTHR_LOS_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{
		UDPBuff[0] |= 1<<7;
									
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.sWord >= ONS3ECard.thresholdSIGMin && saveData.sWord <= ONS3ECard.thresholdSIGMax)
		{		
			alarmThresholds.Signal[0] = saveData.sWord;
			WriteEEPRom( ADDR_THRESHOLD_Signal , saveData.ucByte[0] );
			WriteEEPRom( ADDR_THRESHOLD_Signal + 1, saveData.ucByte[1] );
						
			ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_Signal] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_Signal + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}

//设置PUMP LOW门限
void doSetPumpTHR_LOW_UDP (u8 *pScanPtr)
{
	SHORTVAR	saveData;

	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == PORT2)
	{
		UDPBuff[0] |= 1<<7;
									
		ONS3ECard.DataLen = *pScanPtr++;
		UDPBuff[5] = ONS3ECard.DataLen;

		saveData.ucByte[1] = *pScanPtr++;
		saveData.ucByte[0] = *pScanPtr++;
		UDPBuff[6] = saveData.ucByte[1];
		UDPBuff[7] = saveData.ucByte[0];
		
		LSdataSend(UDPBuff,ONS3ECard.DataLen + FixedDataLen);
		
		if(saveData.sWord >= ONS3ECard.thresholdLOWMin && saveData.sWord <= ONS3ECard.thresholdLOWMax)
		{		
			alarmThresholds.Low[0] = saveData.sWord;
			WriteEEPRom( ADDR_THRESHOLD_LOW , saveData.ucByte[0] );
			WriteEEPRom( ADDR_THRESHOLD_LOW + 1, saveData.ucByte[1] );
						
			ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_LOW] = saveData.ucByte[0];
			ONS3ECard.EEPROMBuff[ADDR_THRESHOLD_LOW + 1] = saveData.ucByte[1];
			EEPROMdataCheck();
		}
		else
		{
			UDPBuff[2] |= 1<<7;
		}
	}
	else
	{		
		UDPBuff[2] |= 1<<7;
	}
}

/*设置ONS3000E card PN信息*/
void doSetCardPN_UDP (u8 *pScanPtr)
{
	u8 ucI;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF)
	{	
		UDPBuff[0] |= 1<<7;
		
		ONS3ECard.DataLen = *pScanPtr++;			
		UDPBuff[5] = ONS3ECard.DataLen;
			
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		{
			ONS3ECard.PN[0][ucI] = *pScanPtr++;	
			UDPBuff[ucI + FixedDataLen] = ONS3ECard.PN[0][ucI];
		}
	}
	else
	{			
		UDPBuff[2] |= 1<<7;
		ONS3ECard.DataLen = 0x00;			
		UDPBuff[5] = ONS3ECard.DataLen;
	}
	
	if(CurPort == CARDSELF)
	{
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		WriteEEPRom( (ADDR_CARD_PN + ucI), ONS3ECard.PN[0][ucI] );
		
		for(ucI=0; ucI<CardPNLen; ucI++)
		ONS3ECard.EEPROMBuff[ADDR_CARD_PN + ucI] = ONS3ECard.PN[0][ucI];
		
		EEPROMdataCheck();
	}
}

/*设置ONS3000E card SN信息*/
void doSetCardSN_UDP (u8 *pScanPtr)
{
	u8 ucI;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF)
	{		
		UDPBuff[0] |= 1<<7;
		
		ONS3ECard.DataLen = *pScanPtr++;			
		UDPBuff[5] = ONS3ECard.DataLen;
			
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		{
			ONS3ECard.SN[0][ucI] = *pScanPtr++;	
			UDPBuff[ucI + FixedDataLen] = ONS3ECard.SN[0][ucI];
		}
	}
	else
	{			
		UDPBuff[2] |= 1<<7;
		ONS3ECard.DataLen = 0x00;			
		UDPBuff[5] = ONS3ECard.DataLen;
	}
	
	if(CurPort == CARDSELF)
	{
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		WriteEEPRom( (ADDR_CARD_SN + ucI), ONS3ECard.SN[0][ucI] );
		
		for(ucI=0; ucI<CardSNLen; ucI++)
		ONS3ECard.EEPROMBuff[ADDR_CARD_SN + ucI] = ONS3ECard.SN[0][ucI];
		
		EEPROMdataCheck();
	}
}

/*设置ONS3000E card描述符信息*/
void doSetCardDESCRIP_UDP (u8 *pScanPtr)
{
	u8 ucI;
	
	CurPort = *pScanPtr++;   //端口号port
	UDPBuff[4] = CurPort;
	
	if(CurPort == CARDSELF)
	{		
		UDPBuff[0] |= 1<<7;
		
		ONS3ECard.DataLen = *pScanPtr++;			
		UDPBuff[5] = ONS3ECard.DataLen;
			
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		{
			ONS3ECard.DESCRIP[0][ucI] = *pScanPtr++;	
			UDPBuff[ucI + FixedDataLen] = ONS3ECard.DESCRIP[0][ucI];
				
			//WriteEEPRom( (ADDR_CARD_DESCRIP + ucI), ONS3ECard.DESCRIP[0][ucI] );
		}
	}
	else
	{			
		UDPBuff[2] |= 1<<7;
		ONS3ECard.DataLen = 0x00;			
		UDPBuff[5] = ONS3ECard.DataLen;
	}
	
	if(CurPort == CARDSELF)
	{
		for(ucI=0; ucI<ONS3ECard.DataLen; ucI++)
		WriteEEPRom( (ADDR_CARD_DESCRIP + ucI), ONS3ECard.DESCRIP[0][ucI] );
		
		for(ucI=0; ucI<CardDESCRIPLen; ucI++)
		ONS3ECard.EEPROMBuff[ADDR_CARD_DESCRIP + ucI] = ONS3ECard.DESCRIP[0][ucI];
		
		EEPROMdataCheck();
	}
}



/***********************************************/



